import { Response, PageResponse } from '@/types/Common';
import {
  CustomerDetail,
  CustomerInfo,
  CustomerPageRequest,
} from '@/types/Customer';
import axios from '../request.js';

export default {
  /**
   * 分页查询接口
   * @param {CustomerPageRequest} body
   * @return {Promise<Response<PageResponse<CustomerInfo>>>}
   */
  page: async (body) => {
    const res = await axios.post(
      `/Api/Client/getList?page=${body.page}&pageSize=${body.pageSize}`,
      body
    );
    return res.data;
  },
  /**
   * 这个和上面接口区别在于，支持parentId(人员类别)的筛选
   * @param {CustomerPageRequest2} body
   * @return {Promise<any>}
   */
  page2: async (body) => {
    const res = await axios.post(
      `/Api/DataList/get_type_client?page=${body.page}&pageSize=${body.pageSize}`,
      body
    );
    return res.data;
  },
  /**
   * 新增接口
   * @param {CustomerInfo} body
   * @return {Promise<Response<CustomerInfo>>}
   */
  add: async (body) => {
    const res = await axios.post('/Api/Client/add', body);
    return res.data;
  },
  /**
   * 详情接口
   * @param {number} id
   * @return {Promise<Response<CustomerDetail>>}
   */
  detail: async (id) => {
    const res = await axios.post(`/Api/Client/get?client_id=${id}`);
    return res.data;
  },
  /**
   * 编辑接口
   * @param {number} clientId
   * @param {CustomerInfo} body
   * @return {Promise<Response<CustomerInfo>>}
   */
  update: async (clientId, body) => {
    const res = await axios.post(
      `/Api/Client/update?client_id=${clientId}`,
      body
    );
    return res.data;
  },
  /**
   * 删除接口
   * @param {number} id
   * @return {Promise<Response<CustomerInfo>>}
   */
  delete: async (id) => {
    const res = await axios.post('/Api/Client/delete', { data: { id } });
    return res.data;
  },
  /**
   * 【
   * @param id
   * @return {Promise<any>}
   */
  getZip: async (id) => {
    const res = await axios.post('/Api/Client/get_client_zip', {
      client_id: id,
    });
    return res.data;
  },
};
